package org.agony2d.view.supportClasses 
{
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import org.agony2d.view.ButtonType;
	
	import org.agony2d.core.agony_internal;
	use namespace agony_internal;
	
	/**
	 * @tips
	 * 		弹起-(滑上...移动设备无)-按下(1-3) - 无效(4)
	 */
public class ImageButtonProp
{
	
	final agony_internal function get hasInvalid() : Boolean { return Boolean(invalidImage) }
	final agony_internal function get press()      : BitmapData { return pressImage }
	final agony_internal function get release()    : BitmapData { return releaseImage }
	final agony_internal function get invalid()    : BitmapData { return invalidImage }
	final agony_internal function get leave()      : BitmapData { return (effectType & ButtonType.PRESS_PRESS) ? pressImage : releaseImage }
	final agony_internal function get hover()      : BitmapData { return (effectType & (ButtonType.PRESS_PRESS | ButtonType.LEAVE_PRESS)) ? pressImage : releaseImage }
	
	
	agony_internal function initialize( source:BitmapData, hasInvalid:Boolean) : void
	{
		var width:Number, height:Number
		var rect:Rectangle
		var point:Point
		
		width   =  (this is ImageCheckBoxProp) ? source.width / 2 : source.width
		height  =  hasInvalid ? (source.height / 3) : (source.height / 2)
		point   =  new Point()
		rect    =  new Rectangle(0, 0, width, height)
		
		if (hasInvalid)
		{
			pressImage = new BitmapData(width, height, true, 0x0)
			pressImage.copyPixels(source, rect, point)
			releaseImage = new BitmapData(width, height, true, 0x0)
			rect.y = height
			releaseImage.copyPixels(source, rect, point)
			invalidImage = new BitmapData(width, height, true, 0x0)
			rect.y = height * 2
			invalidImage.copyPixels(source, rect, point)
		}
		
		else
		{
			pressImage = new BitmapData(width, height, true, 0x0)
			pressImage.copyPixels(source, rect, point)
			releaseImage = new BitmapData(width, height, true, 0x0)
			rect.y = height
			releaseImage.copyPixels(source, rect, point)
		}
		
		source.dispose()
		source = null
	}
	
	agony_internal function dispose() : void
	{
		pressImage.dispose()
		pressImage = null
		releaseImage.dispose()
		releaseImage = null
		if (invalidImage)
		{
			invalidImage.dispose()
			invalidImage = null
		}
	}
	
	
	agony_internal var pressImage:BitmapData, releaseImage:BitmapData, invalidImage:BitmapData
	
	agony_internal var effectType:int
}
}